package com.shengzhe.ostudent.utils.request;

import javax.servlet.http.HttpServletRequest;
import java.sql.Connection;

public class RequestLocalHolder {
    private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<>();
    private static final ThreadLocal<Connection> connectionThreadLocal = new ThreadLocal<>();


    public static String getPathInfoByThreadLocal() {
        return getHttpServletRequest().getPathInfo();
    }

    public static void setHttpServletRequest(HttpServletRequest request) {
        requestHolder.set(request);
    }

    public static HttpServletRequest getHttpServletRequest() {
        return requestHolder.get();
    }

    public static void setConnectionForThreadLocal(Connection connection) {
        connectionThreadLocal.set(connection);
    }

    public static Connection getConnectionByThreadLocal() {
        return connectionThreadLocal.get();
    }


    public static void clear() {
        connectionThreadLocal.remove();
        requestHolder.remove();
    }
}